package fr.isen.smssender.sms;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Button;

import java.util.Timer;
import java.util.TimerTask;


public class SendSmsActivity extends Activity {
    
    private String number;
    private String sms;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        Bundle bundle= getIntent().getExtras();
        number = bundle.getString("number");
        sms = bundle.getString("sms");

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask(){
            @Override
            public void run(){
                    TimerMethod();    
            }
        },0,1 * 1000);
        
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(number,null,sms,null,null);
        stopService(this.getIntent());

    }

    private void TimerMethod(){
        this.runOnUiThread(Timer_Tick);
    }
    
    private Runnable Timer_Tick = new Runnable() {
        boolean fg = false;
        @Override
        public void run() {
            //To change body of implemented methods use File | Settings | File Templates.
            if (fg){
                Log.i("ENI", "Actif");
                fg = false;
            }else{
                Log.i("ENI", "Inactif");
                fg = true;
            }
        }
    };
}